package org.zxp.javacheck.shallowdeepcopy.shallow;

import org.apache.commons.beanutils.BeanUtils;

import java.lang.reflect.InvocationTargetException;

/**
 * @program: effectiveJava
 * @description: apache的BeanUtil拷贝是浅拷贝不是深拷贝
 * @author: X-Pacific zhang
 * @create: 2019-11-29 18:04
 **/
public class BeanUtilCopy {
    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException {
        Subject subject = new Subject("yuwen");
        Student studentA = new Student();
        studentA.setSubject(subject);
        studentA.setName("Lynn");
        studentA.setAge(20);

        Student studentB = new Student();
        BeanUtils.copyProperties(studentB,studentA);
        Subject subjectB = studentB.getSubject();
        subjectB.setName("lishi");

        //subject对象是同一个的对象
        System.out.println("studentA:" + studentA.toString());
        System.out.println("studentB:" + studentB.toString());


    }
}
